#!encoding:utf-8


import jieba

excludes={'：', '，', '；', '。', '！', '？', '\n'}

str_d = dict()
with open('zbkq.txt', 'r') as f:
    for i in f.readlines():
        words = jieba.lcut(i)
        for w in words:
            if w not in excludes:
                str_d[w] = str_d.setdefault(w, 0) + 1

new_word=list(sorted(str_d.items(), key= lambda x:x[1], reverse = True))
#import operator
#print(sorted(str_d.items(), key=operator.itemgetter(1), reverse = True))
#print(sorted(zip(str_d.values(), str_d.keys()), reverse = True))
with open('word_zbkq.csv', 'w', encoding='gb2312') as f:
    for w in new_word:
        f.write('{},{}\n'.format(w[0],w[1]))

